<template>
  <div class="app-container editcss">
    <el-row :gutter="0" class="el-card is-always-shadow el-card__body  card_contents" style="padding: 0px;">
      <el-col>
        <el-row class="content_h">
          <el-col class="title_tops">
            <div class="title_tops_t">
              <div class="title_top_E">Authority Management</div>
              <div class="title_top_C">等级权限管理</div>
            </div>
            <div class="title_tops_b" @click="tabGo">
              <img src="../../assets/iconfont/arrow-left-circle.png" alt="" srcset="">
              <span>返回医护管理</span>
            </div>
          </el-col>
          <el-col class="screen_case">
            <div class="screen_case_amount">
              <span class="screen_case_amount_lable">等级数量：</span>
              <span class="screen_case_amount_value">{{ totality }}个</span>
            </div>
            <construction title="新建等级权限" @addition="additions" />
          </el-col>
        </el-row>
      </el-col>
      <el-col class="dialog_title_ch_conter_operate  card_contents_tex">
        <el-table :data="tableData" fit style="width: 100%" header-row-class-name="hrcn" row-class-name="rcn">
          <el-table-column type="index" align="center" label="序号" width="130">
          </el-table-column>
          <el-table-column align="" label="等级权限标题">
            <template slot-scope="scope">
              {{ scope.row.title }}
            </template>
          </el-table-column>
          <el-table-column align="center" label="创建时间" width="337">
            <template slot-scope="scope">
              {{ parseTime(scope.row.createTime, '{y}.{m}.{d} {h}:{i}:{s}') }}
            </template>
          </el-table-column>
          <el-table-column fixed="right" align="center" label="操作" width="200">
            <template slot-scope="scope">
              <el-button class="editbtn" type="text" size="small" @click="editClick(scope.row)">
                <img src="../../assets/iconfont/edit.png" alt="">
                编辑</el-button>
              <el-button class="delbtn" type="text" size="small" @click="delClick(scope.row)">
                <img src="../../assets/iconfont/icondel.png" alt="">
                删除</el-button>
            </template>
          </el-table-column>
        </el-table>
        <div class="paginationblock" v-if="tableData.length > 0">
          <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
            :current-page="pageData.pageNo" :page-sizes="[10, 20, 30, 40]" :page-size="pageData.pageSize"
            :background="true" layout="total, sizes, prev, pager, next, jumper" :total="totality">
          </el-pagination>
        </div>
      </el-col>
      <!-- <el-col class="card_contents_footer">
        <el-button type="primary" class="ch_button_seav" @click="tabGo">
          <img class="ch_button_img_seav" src="../../assets/iconfont/icon-seavicon.png" alt="" srcset="">
          <div>提交</div>
        </el-button>
      </el-col> -->
    </el-row>

    <!-- 新增 编辑 -->
    <el-dialog :visible.sync="addDialogVisible" custom-class="addeteDialog" :modal='true'>
      <div slot="title">
        <span class="title_top_E">Service Record</span>
        <span class="title_top_C">{{ addFrom.permissionId ? '编辑' : '新建' }}等级权限</span>
      </div>
      <div class="addeteDialog_conter">
        <div class="top_content">
          <screenSelect title="等级权限标题：" type='input' style="margin-right: 0;" v-model="addFrom.title"
            :isValue='addFrom.title' placeholder="请输入等级权限标题" @transfer="valueHeld($event, 'title')" width='100%'
            position="top" />
          <div class="content_checkbox">
            <div class="title_che">小程序权限：</div>
            <div class="title_che_sup">{{iSoperationProject==0?'自购':'设备'}}服务</div>
            <el-checkbox-group v-model="addFrom.appletIdList">
              <el-checkbox v-for="(item, index) in checkDataL" :key="index" :label="item.appletId">{{ item.appletMenuName
              }}</el-checkbox>
            </el-checkbox-group>
          </div>
        </div>
        <div class="footer_submit">
          <el-button type="primary" class="ch_button_seav" @click="addsubmit">
            <img class="ch_button_img_seav" src="../../assets/iconfont/icon-seavicon.png" alt="" srcset="">
            <div>提交</div>
          </el-button>
        </div>
      </div>

    </el-dialog>
    <!-- 删除 -->
    <el-dialog title="提示" :visible.sync="delDialogVisible" custom-class="deleteDialog" :show-close='false' :modal='true'>
      <span class="deleteDialogSpanconter">您确认要删除此等级权限？</span>
      <span slot="footer" class="dialog-footer">
        <el-button type="danger" @click="delHeld">确认删除</el-button>
        <el-button type="primary" @click="delDialogVisible = false">取消</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import construction from '@/components/construction/index.vue'
import screenSelect from '@/components/screenSelect/index.vue'
import { getPermissionList, getPermissionAdd, getPermissionDetail, getPermissionDelete } from '@/api/medicalauthority'
import {  getHospitalDetail } from '@/api/organizational'
import { getAppletList } from '@/api/common'
import { getHosPartDetail } from '@/api/administrative'
import {
  mapGetters
} from 'vuex'
export default {
  name: "Field",
  components: {
    construction,
    screenSelect,
  },
  computed: {
    ...mapGetters([
      'permissionList'
    ])
  },
  data() {
    return {
      delDialogVisible: false,
      addDialogVisible: false,
      iSoperationProject: 0,
      addFrom: {
        appletIdList: []
      },
      checkDataL: [],
      imageUrl: '',
      tableData: [],
      pageData: {
        pageNo: 1,
        pageSize: 10
      },
      totality: 0,//总数
    };
  },
  mounted() {
    console.log(this.$route);
    this.getList()
    this.getAppList()
  },
  methods: {
    getAppList() {
      getAppletList(this.$route.params.id).then(res => {
        if (res.code == 200) {
          const checkDataL = []
          res.data.appletMenuList.map(item=>{
            if(item.appletId!=4 && item.appletMenuName!='设备管理'){
              checkDataL.push(item)
            }
          })
          // this.checkDataL = res.data.appletMenuList
          this.checkDataL = checkDataL
        }
      })
    },
    getList() {
		getHosPartDetail(this.$route.params.id).then(res => {
		  if (res.code == 200) {
			getHospitalDetail(res.data.hospitalDepart.hospitalId).then(res => {
			  if (res.code == 200) {
				  this.iSoperationProject = res.data.hospital.operationProject
			  }else{
				  this.$Toast(res.message)
			  }
			})
		  }else{
			  this.$Toast(res.message)
		  }
		})
		
      getPermissionList(this.$route.params.id, this.pageData).then(res => {
        if (res.code == 200) {
          this.tableData = res.data.permissionPage.records
          this.totality = res.data.permissionPage.total
        }
      })
    },
    tabGo() {
      this.$router.go(-1)
    },
    valueHeld(childParam, fatherparam) {
      this.addFrom[fatherparam] = childParam
    },
    delClick(row) {
      this.delDialogVisible = true
      this.addFrom = row
      console.log(row);
    },
    // 确认删除
    delHeld() {
      getPermissionDelete(this.addFrom.permissionId).then(res => {
        if (res.code == 200) {
          this.$Toast('删除成功')
          this.delDialogVisible = false
          this.getList()
        }
      })
    },
    editClick(row) {
      getPermissionDetail(row.permissionId).then(res => {
        if (res.code == 200) {
          this.addDialogVisible = true
          this.addFrom = res.data.permission
        }
      })
    },
    additions(e) {
      this.addFrom = { appletIdList: [] }
      this.addDialogVisible = e
    },
    // 提交
    addsubmit() {
      this.addFrom.deptId = this.$route.params.id
      console.log(this.addFrom);
      if(!this.addFrom.title || this.addFrom.title==''){
        this.$Toast('请输入标题')
        return
      }
      if(this.addFrom.appletIdList.length==0){
        this.$Toast('请勾选权限')
        return
      }
      getPermissionAdd(this.addFrom).then(res => {
        if (res.code == 200) {
          this.$Toast('操作成功')
          this.getList()
          this.addDialogVisible = false
        }
      })
    },
    handleSizeChange(val) {
      this.pageData.pageSize = val
      this.getList()
    },
    handleCurrentChange(val) {
      this.pageData.pageNo = val
      this.getList()
    },
  }
}
</script>

<style lang="scss" scoped>
::v-deep .hrcn th {
  background-color: #FFFFFF;
  color: #989898;
  font-size: 15px;
  font-weight: 400;
}

::v-deep .hrcn th .cell {
  border-right: 1px solid #EFEFEF;
}

::v-deep .hrcn th:last-child .cell {
  border-right: none;
}

::v-deep .rcn {
  color: #000;
  font-size: 16px;
  font-weight: 400;
}

.card_contents {
  height: calc(100% - 1px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;

  .card_contents_tex {
    flex: 1;
    overflow-y: auto;
    margin-bottom: 20px;
  }

  .card_contents_footer {
    padding: 16px 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-top: 1px solid #EFEFEF;
  }
}

.content_h {
  height: 149px;
  border-radius: 5px;
  padding: 0px;
  border-bottom: 1px solid #EFEFEF;
}

.title_tops {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 0 20px;
  height: 79px;
  border-bottom: 1px solid #EFEFEF;

  .title_tops_t {
    display: flex;
    flex-direction: column;
    justify-content: center;
  }

  .title_tops_b {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: 28px;
    cursor: pointer;

    img {
      width: 24px;
      height: 24px;
      margin-right: 5px;
    }

    span {
      font-size: 16px;
      font-weight: 400;
      color: #000;
    }
  }
}

.screen_case_title {
  font-size: 16px;
  font-weight: 400;
  color: #000;
  margin-right: 35px;
}

.title_top_E {
  font-size: 12px;
  font-weight: 400;
  color: #9898989E;
}

.title_top_C {
  font-size: 18px;
  font-weight: 400;
  color: #000;
}

.screen_case {
  display: flex;
  align-items: center;
  padding: 15px 30px;
}

.screen_case_amount {
  .screen_case_amount_lable {
    font-size: 15px;
    color: #989898;
  }

  .screen_case_amount_value {
    font-size: 16px;
    color: #000;
  }
}

::v-deep .ch_button_seav {
  padding: 7px 27px;

  span {
    display: flex;
    align-items: center;
    justify-content: center;

    div {
      font-size: 16px;
      font-weight: 400;
      margin-left: 10px;
    }
  }
}

.ch_button_img_seav {
  width: 24px;
  height: 24px;
}

.dialog_title_ch_conter_operate {
  // padding: 24px 35px;
  // border: 1px solid #EBEBEB;
  border-radius: 2px;
  // display: flex;
  // align-items: center;
}

::v-deep .editbtn span,
::v-deep .delbtn span {
  display: flex;
  align-items: center;
  justify-content: center;
}

.editbtn,
.delbtn {
  img {
    width: 15px;
    height: 15px;
  }
}

.delbtn {
  color: #FE294D;
  margin-left: 57px;
}

.editbtn:active,
.delbtn:active {
  opacity: .6;
}

.el-dialog__wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
}

//新增弹窗
::v-deep .addeteDialog {
  background-color: #FFFFFF;
  width: 1268px;
  // height: 764px;
  border-radius: 6px;
  box-shadow: 0 0 10px #60778E47;
  display: flex;
  flex-direction: column;
}

::v-deep .addeteDialog .el-dialog__header {
  height: 80px;

  div {
    display: flex;
    flex-direction: column;
  }

  border-bottom: 1px solid #EFEFEF;

  // 自定义弹窗x号
  .el-dialog__close::before {
    content: ' ';
    background: url(../../assets/iconfont/x-circle.png);
    background-size: 20px 20px;
    width: 20px;
    height: 20px;
    display: flex;
  }

  .el-dialog__close:active::before {
    background: url(../../assets/iconfont/x-circleactive.png);
    background-size: 20px 20px;
  }
}

::v-deep .addeteDialog .el-dialog__body {
  padding: 17px 20px;

  .addeteDialog_conter {
    border: 1px solid #EFEFEF;
    flex: auto;
    display: flex;
    flex-direction: column;

    .top_content {
      flex: 1;
      min-height: 200px;
      max-height: 580px;
      overflow-y: auto;
      padding: 20px 23px;

      .content_checkbox {
        .title_che {
          margin-top: 20px;
          margin-bottom: 10px;
          font-size: 15px;
          font-weight: 400;
          color: #989898;
        }

        .title_che_sup {
          font-size: 13px;
          font-weight: 400;
          color: #414141;
        }

        .el-checkbox {
          margin-top: 8px;
        }

      }
    }

    .footer_submit {
      display: flex;
      align-items: center;
      justify-content: center;
      border-top: 1px solid #EFEFEF;
      padding: 10px 0 15px 0;
    }
  }
}

//删除弹窗
::v-deep .deleteDialog {
  background-color: #FFFFFF;
  width: 552px;
  height: 332px;
  border-radius: 6px;
  box-shadow: 0 0 10px #60778E47;
  display: flex;
  flex-direction: column;
}

::v-deep .deleteDialog .el-dialog__header {
  .el-dialog__title {
    color: #000;
    font-size: 18px;
    font-weight: 400;
  }

  border-bottom: 1px solid #EFEFEF;
  // 自定义弹窗x号
  // .el-dialog__close::before{
  //   content:' ';
  //   background: url(../../assets/iconfont/x-circle.png);
  //   background-size: 20px 20px;
  //   width: 20px;
  //   height: 20px;
  //   display: flex;
  // }
  // .el-dialog__close:active::before{
  //   background: url(../../assets/iconfont/x-circleactive.png);
  //   background-size: 20px 20px;
  // }
}

::v-deep .deleteDialogSpanconter {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  font-size: 18px;
  font-weight: 400;
  color: #000;
}

::v-deep .deleteDialog .el-dialog__body {
  flex: 1;
}

.deleteDialog .dialog-footer {
  display: flex;
  justify-content: center;
  align-items: center;

  button {
    width: 120px;
    height: 38px;
    border-radius: 1px;
    font-size: 16px;
    font-weight: 400;
    color: #FFFFFF;
  }

  button:active {
    opacity: .6;
  }

  button:nth-child(1) {
    margin-right: 32px;
    background-color: #FE294D;
    border-color: #FE294D;
  }

  button:nth-child(2) {
    background-color: #0584FE;
    border-color: #0584FE;
  }
}
</style>
